package com.leostadyn.stackfarm.timestatistics.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.leostadyn.stackfarm.timestatistics.R;
import com.leostadyn.stackfarm.timestatistics.model.bean.StaffTimeRecordBean;

import java.util.List;

public class DialogProjectListAdapter extends RecyclerView.Adapter {
    private Context mContext;
    private List<StaffTimeRecordBean.DataListBean> dataListBeans;
    private double count = 0;

    public DialogProjectListAdapter(Context mContext, List<StaffTimeRecordBean.DataListBean> dataListBeans) {
        this.mContext = mContext;
        if (dataListBeans != null) {
            this.dataListBeans = dataListBeans;
        }
    }

    /* public void setDataListBeans( List<StaffTimeRecordBean.DataListBean> dataListBeans) {
         this.dataListBeans.clear();
         if (dataListBeans != null && dataListBeans.size() > 0) {
             this.dataListBeans.addAll(dataListBeans);
         }
         notifyDataSetChanged();

     }*/
    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_dialog_list, viewGroup, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        StaffTimeRecordBean.DataListBean dataListBean = dataListBeans.get(i);
        if (viewHolder instanceof ViewHolder) {
            ((ViewHolder) viewHolder).projectName.setText(dataListBean.getProjectName());
            ((ViewHolder) viewHolder).taskTime.setText(dataListBean.getTaskTime() + "天");
        }

    }

    public double getCount() {
        for (StaffTimeRecordBean.DataListBean data : dataListBeans) {
            count = count + data.getTaskTime();
        }
        return count;
    }


    @Override
    public int getItemCount() {
        if (dataListBeans != null) {
            return dataListBeans.size();
        }
        return 0;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView projectName;
        TextView taskTime;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            projectName = itemView.findViewById(R.id.project_name);
            taskTime = itemView.findViewById(R.id.task_time);


        }
    }
}
